<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>002-i值问题.html</title>
</head>
<body>
	<button>btn1</button>
	<button>btn2</button>
	<button>btn3</button>
	<button>btn4</button>
</body>
<script>
	var aBtn = document.getElementsByTagName('button')
	/*
	for(var i = 0;i<aBtn.length;i++){
		aBtn[i].onclick = function(){
			console.log(i)
		}
	}
	console.log(i)
	*/
	/*
	for(var i = 0;i<aBtn.length;i++){
		aBtn[i].index = i
		aBtn[i].onclick = function(){
			console.log(this.index)
		}
	}
	*/
	/*
	for(var i = 0;i<aBtn.length;i++){
		(function(i){
			aBtn[i].onclick = function(){
						console.log(i)
					}
		})(i);
	}
	*/
	
	for(let i =0;i<aBtn.length;i++){
		aBtn[i].onclick = function(){
			console.log(i)
		}
	}
</script>
</html>